var expandableTabs, slidingContent;
$(document).ready(function() {
	// handling expandable tabs
	expandableTabs = $('.expandable_tab');
	slidingContent = $('.content');

	$(document).on('click', '.expandable_tab', function(e) {
		var clickedTab = $(this);
		var contentBlock = $('#' + $(this).attr('id') + '_content');
		if ($(contentBlock).is(':visible')) {
			$(contentBlock).slideUp('fast', function() {
				changeArrowIco($(clickedTab));
			});
			return;
		}

		$(slidingContent).each(function(i, el) {
			$(el).slideUp('fast', function() {
				$('.expanded').removeClass('expanded');
			});
		}).promise().done(function() {
			contentBlock.slideToggle('fast', function() {
				changeArrowIco($(clickedTab));
			});
		});
	});

	var changeArrowIco = function(context) {
		$(context).find('.tab_arrow').toggleClass('expanded');
	};

	// zamienniki główna
	$(document).on('click', '#replacement_submit', function() {

		$.ajax({
			url: "http://m.wixeurope.com/m/Ajax/ReplacementFilterList.aspx?value="+ $('#replacement_input').val() +"&languageName=polish",
			type: "GET",
			dataType: "json",
			beforeSend: function() {
				$.mobile.loading('show', {text: 'Ładowanie'});
			},
			success: function(data) {
				replacementsList = data.bindings;
				$.mobile.loading('hide');
				return $.mobile.changePage('replacements_filter.html', {
					transition: 'slide'
				});
			}
		});

	});

});